def show(sxpr, out=sys.stdout):
"""Print an sxpr in bracketed (lisp-style) syntax.
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
out.write(k_list_open)
i = 0
for x in sxpr:
def show_xml(sxpr, out=sys.stdout):
"""Print an sxpr in XML syntax.
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
element = name(sxpr)
out.write('<%s' % element)
for attr in attributes(sxpr):
sxpr sxpr
elt element type
"""
- return (isinstance(sxpr, types.ListType)
+ return (isinstance(sxpr, (types.ListType, types.TupleType))
and len(sxpr)
and (None == elt or sxpr[0] == elt))
val = None
if isinstance(sxpr, types.StringType):
val = sxpr
- elif isinstance(sxpr, types.ListType) and len(sxpr):
+ elif isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr):
val = sxpr[0]
return val
returns attribute list
"""
val = []
- if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+ if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
attr = sxpr[1]
if elementp(attr, k_attr_open):
val = attr[1:]
returns children (filtered by elt if specified)
"""
val = []
- if isinstance(sxpr, types.ListType) and len(sxpr) > 1:
+ if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1:
i = 1
x = sxpr[i]
if elementp(x, k_attr_open):
return s-exp or val
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
for n in sxpr:
if has_id(n, id):
val = n
return s-exp or val
"""
- if isinstance(sxpr, types.ListType):
+ if isinstance(sxpr, (types.ListType, types.TupleType)):
for n in sxpr:
if has_id(n, id):
val = n
yield (sxpr, ctxt)
i = 0
for n in children(sxpr):
- if isinstance(n, types.ListType):
+ if isinstance(n, (types.ListType, types.TupleType)):
# Calling elements() recursively does not generate recursively,
# it just returns a generator object. So we must iterate over it.
for v in elements(n, (i, sxpr, ctxt)):